package com.lik888.web1.service.impl;

import cn.hutool.core.util.RandomUtil;
import com.lik888.web1.entity.AgentTable;
import com.lik888.web1.mapper.AgentTableMapper;
import com.lik888.web1.service.IAgentTableService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Random;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2025-11-14
 */
@Service
@RequiredArgsConstructor
public class AgentTableServiceImpl extends ServiceImpl<AgentTableMapper, AgentTable> implements IAgentTableService {

    private final AgentTableMapper agentTableMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean addService(AgentTable agentTable) {
       Long agentNumber = Long.valueOf(RandomUtil.randomNumbers(10));
       //查询是否存在
       AgentTable agentTable1 = baseMapper.selectById(agentNumber);
       if(agentTable1!=null){
           return false;
       }
       //查询agent_number是否存在
       agentTable1 = agentTableMapper.selectById(agentNumber);
       if(agentTable1!=null){
           return false;
       }
       agentTable.setAgentNumber(agentNumber);
        agentTableMapper.insert(agentTable);
        return true;

    }
}
